import 'package:dio/dio.dart';
import 'package:flutter_application_1/models/home_banner_data.dart';
import 'package:flutter_application_1/models/home_article_data.dart';
import 'package:flutter_application_1/http/dio_instance.dart';

class Api {
  static Api instance = Api._();

  Api._();

  // 获取banner
  Future<List<HomeBannerData>> getBanner() async {
    Response response = await DioInstance.instance().get(path: '/banner/json');
    HomeBannerListData homeBannerData =
        HomeBannerListData.fromJson(response.data);
    return homeBannerData.bannerList ?? [];
  }

  // 获取文章list
  Future<List<Datas>> getArticleList(conut) async {
    Response response =
        await DioInstance.instance().get(path: '/article/list/${conut.toString()}/json');
    HomeListData homeArticleData = HomeListData.fromJson(response.data);
    return homeArticleData.datas ?? [];
  }

  // 获取文章Toplist
  Future<List<Datas>> getArticleTopList() async {
    Response response =
        await DioInstance.instance().get(path: '/article/top/json');
    HomeTopListData homeArticleData = HomeTopListData.fromJson(response.data);
    return homeArticleData.topList ?? [];
  }
}
